#include "State.h"
#include "Transfer.h"
#include "Machine.h"


void State::ProcessChars(CharTypePtr character)
{
    if (_currentChar = character)
        _transfersMap[_currentChar]->Perform();
}

void State::AddAction(ActionPtr action)
{
    _actions.append(action);
}

void State::SetMachine(Machine* m)
{
    _machine = m;
}

void State::RegisterTransfer(TransferPtr transfer, const CharTypeList& charList)
{
    Q_FOREACH(CharTypePtr character, charList)
        _transfersMap.insert(character, transfer);
}

void State::PerformActions()
{
    Q_FOREACH(ActionPtr action, _actions)
        action->Perform();
}

void State::CancelActions()
{
    Q_FOREACH(ActionPtr action, _actions)
        action->Cancel();
}

CharTypePtr State::CurrentChar()
{
    return _currentChar;
}

CharTypeList State::Chars()
{
    return _transfersMap.keys();    
}